/*
 *     Copyright 2006 Robert Burrell Donkin
 *  
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package rat.element;

/**
 * Typesafe enum of element types.
 *
 * <p>Contains some helper methods to determine element types based on
 * file names and contents as well.</p>
 */
public final class ElementTypeEnum {
    private final String name;

    public static final ElementTypeEnum ARCHIVE =
        new ElementTypeEnum("Archive");
    public static final ElementTypeEnum BINARY =
        new ElementTypeEnum("Binary");
    public static final ElementTypeEnum DIRECTORY =
        new ElementTypeEnum("Directory");
    public static final ElementTypeEnum NOTE = 
        new ElementTypeEnum("Note");
    public static final ElementTypeEnum STANDARD_CONTENT =
        new ElementTypeEnum("Standard Content");

    public static final ElementTypeEnum UNKNOWN =
        new ElementTypeEnum("Unknown");

    private ElementTypeEnum(String name) {
        this.name = name;
    }

    public String toString() {
        return name;
    }

    /**
     * Tries to guess a file's type by its name, returns UNKNOWN if
     * the file name is not known.
     *
     * <p>Does not consult {BinaryElement#isBinary(java.io.InputStream
     * isBinary with the Stream argument}.</p>
     */
    public static ElementTypeEnum guessType(final String name) {
        ElementTypeEnum result = UNKNOWN;
        if (NoteElement.isNote(name)) {
            result = NOTE;
        } else if (ArchiveElement.isArchive(name)) {
            result = ARCHIVE;
        } else if (BinaryElement.isNonBinary(name)) {
            result = STANDARD_CONTENT;
        } else if (BinaryElement.isBinary(name)) {
            result = BINARY;
        }
        return result;
    }

}